package com.fr.football;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.HashMap;
import java.util.Map;

import com.alibaba.fastjson.JSON;

public class CleanData {
	private static final String basePath = "F:\\data\\";
	
	public static void main(String[] args) {
		try {
			Map<Long, FileWriter> map = new HashMap<>();
			FileReader fr = new FileReader(basePath + "source1.txt");
			BufferedReader br = new BufferedReader(fr);
			String line = br.readLine();
			while (line != null) {
				line = line.toUpperCase().replace("LISTODDS", "listOdds");
				FootballInfo fi = JSON.parseObject(line, FootballInfo.class);
				if (fi != null) {
					int result = fi.getHOST_GOAL() > fi.getGUEST_GOAL() ? 3 : fi.getHOST_GOAL() == fi.getGUEST_GOAL() ? 1 : 0;
					for(GamblingInfo gi : fi.getListOdds()) {
						long companyId = gi.getSOURCE_COMPANY_ID();
						FileWriter fw = map.get(companyId);
						if (fw == null) {
							File f = new File(basePath + companyId + ".txt");
							if(!f.exists()) {
								f.createNewFile();
							}
							fw = new FileWriter(f);
							map.put(companyId, fw);
						}
						fw.append(gi.getFIRST_WIN() + "\t");
						fw.append(gi.getFIRST_SAME() + "\t");
						fw.append(gi.getFIRST_LOST() + "\t");
						fw.append(gi.getWIN() + "\t");
						fw.append(gi.getSAME() + "\t");
						fw.append(gi.getLOST() + "\t");
						fw.append(result + "\n");
					}
				}
				line = br.readLine();
			}
			for(FileWriter fw : map.values()) {
				fw.close();
			}
			br.close();
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
